package com.twotiger.and.activity;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import app.twotiger.p2p.R;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.twotiger.and.Constants;
import com.twotiger.and.TwoTigerApp;
import com.twotiger.and.activity.account.cash.CashPage;
import com.twotiger.and.activity.account.invested.InverstedRecordPage;
import com.twotiger.and.activity.account.recharge.RechargePage;
import com.twotiger.and.activity.base.BaseActivity;
import com.twotiger.and.activity.base.BaseHandler;
import com.twotiger.and.activity.current.CurrentHost;
import com.twotiger.and.activity.current.CurrentInputAmountPage;
import com.twotiger.and.activity.others.MorePage;
import com.twotiger.and.activity.project.ExperienceInverstConfirmPage;
import com.twotiger.and.activity.project.InverstInputAmountPage;
import com.twotiger.and.activity.project.InvestFailurePage;
import com.twotiger.and.activity.project.InvestSuccessPage;
import com.twotiger.and.activity.project.ProjectDetailPage;
import com.twotiger.and.activity.project.Projectpage;
import com.twotiger.and.activity.project.debt.DebtInverstInputAmountPage;
import com.twotiger.and.activity.user.LoginPage;
import com.twotiger.and.bean.Basebean;
import com.twotiger.and.bean.BroswerUrl;
import com.twotiger.and.bean.CashBank;
import com.twotiger.and.bean.ConstantDataUnit;
import com.twotiger.and.bean.Contact;
import com.twotiger.and.bean.CurrentProject;
import com.twotiger.and.bean.DebtProjectdetailData;
import com.twotiger.and.bean.ExperienceOrder;
import com.twotiger.and.bean.Order;
import com.twotiger.and.bean.ProjectdetailData;
import com.twotiger.and.bean.Share;
import com.twotiger.and.bean.User;
import com.twotiger.and.bean.WithdrawBank;
import com.twotiger.and.util.ArithUtils;
import com.twotiger.and.util.EaseHXUtils;
import com.twotiger.and.util.IntentUtil;
import com.twotiger.and.util.KeyboradListener;
import com.twotiger.and.util.ListUtils;
import com.twotiger.and.util.LogUtil;
import com.twotiger.and.util.PromptManager;
import com.twotiger.and.util.PromptManager.ClickListener;
import com.twotiger.and.util.PromptManager.ReChargeClickListener;
import com.twotiger.and.util.StringUtils;
import com.twotiger.and.util.TimeUtils;
import com.twotiger.and.util.Tools;
import com.twotiger.and.util.URLUtil;
import com.twotiger.and.util.UmShearUtils;
import com.twotiger.and.util.ViewUtils;
import com.twotiger.and.web.JavaScriptInterface;
import com.umeng.analytics.MobclickAgent;
import com.umeng.analytics.MobclickAgentJSInterface;

/**
 * webView
 * @Description: TODO(这里描述这个类的作用) 
 * @Author douxy
 * @Date 2015年8月18日 下午8:59:58
 */
public class WebViewPage extends BaseActivity {

    public static final String BACK_DIRECT = "back_direct";
    public static final String BACK_TO_HOME = "back_to_home";

    public static final String TYPE_INVESTENDLESS = "investendless"; //业务流程---黑洞计划投资
    public static final String TYPE_INVESTTENDER = "investtender";//业务流程---直投项目
    public static final String TYPE_INVESTDEBT = "investdebt";//业务流程---转让项目投资
    public static final String TYPE_CASE = "case"; //业务流程---取现
    public static final String TYPE_PAYMENT_REGIST = "payment_regist";//业务流程---开通三方
    public static final String TYPE_RECHARGE_HF_DERECT = "recharge_hf_derect";//业务流程---汇付充值---直接充值
    public static final String TYPE_RECHARGE_HF_ORDER = "recharge_hf_order";//业务流程---汇付充值---订单充值
    public static final String TYPE_OPEN_AUTO_PROJECT = "open_auto_project";//业务流程---授权开通自动投资

    private final String mPageName = "WebViewPage";
    public static final String SEARCH_HISTORY = "WebViewPage";
    public static final String TAG_CLICK_TELE = "telephone";
    public static final String TAG_CLICK_QQ = "qq";

    private WebView mWebView;
    private HashMap<String, String> params;
    private TextView sub_title_center_tv;
    private LinearLayout sub_title_left_ll;
    private ImageView sub_title_left_bt;
    private static final int GETASSERTSUCCES = 0;
    private static final int GETASSERTFAIL = 1;
    private ProgressBar web_progressbar_title;

    private static final int LOOPGETUSERBANKCARD = 2; //收到消息即请求银行卡列表
    private static final int GETBANKSUCCES = 3;
    private static final int GETBANKFAIL = 4;

    protected static final int OPENPAYMENTSUCCES = 5;
    protected static final int OPENPAYMENTFAIL = 6;

    private final static int GET_USERINFO_SSUCESS = 7;
    private final static int GET_USERINFO_FAIL = 8;

    private static final int GETDETAILSUCCES = 9;
    private static final int GETDETAILFAIL = 10;

    public static final int GOTO_BOUTIQUEPAGE = 11;
    public static final int GOTO_PROJECTEPAGE = 12;
    public static final int GOTO_ACCOUNTEPAGE = 13;
    public static final int GOTO_MOREPAGE = 14;
    public static final int GOTO_CURRENTPAGE = 15;
    public static final int TO_SHARE = 16;
    public static final int TO_SHARE_PRE = 17;
    public static final int TO_CHANGE_COUPON = 18;
    public static final int TO_SYSBROWSER = 19;

    private static final int GETCURRENTPROJECTSUCCES = 20;
    private static final int GETCURRENTPROJECTFAIL = 21;
    private static final int OPENAUTOCURRENTPROJECTSUCCES = 22;
    private static final int OPENAUTOCURRENTPROJECTFAIL = 23;

    private static final int GETCONTACTSUCCESS = 24;
    private static final int GETCONTACTFAILURE = 25;

    protected static final int EXCHANGECOUPONSUCCES = 26;
    protected static final int EXCHANGECOUPONFAIL = 27;

    public static final int TO_SHARE_CHANNEL = 28;

    public static final int GOTO_PROJECTEPAGE_TRANS = 29;
    public static final int GOTO_CURRENT_ENTER = 30;
    public static final int GOTO_CHATPAGE = 31;

    private static final int GETDEBTDETAILSUCCES = 32;
    private static final int GETDEBTDETAILFAIL = 33;

    private String errorHtml = "";
    private Button to_inverst;
    private LinearLayout ll_bottom;
    private Basebean projectDetail;
    //    private ProjectCommingJob projectCommingJob;

    public boolean isFinish; //JavaScriptinterface 中会控制isFinish
    private String check_tag; //绑卡成功与否 的判断规则

    private String msg_url;
    private ImageView sub_title_right_bt;
    private String business_type; //区分业务类型
    private String back_mode; //点击左上角的箭头 是直接退出webviewpage还是web页面一步一步返回

    private String tiger_host;

    private TextView sub_title_right_tv;

    private Share mSharePre; //分享的准备数据

    private String tag_click; //区分用户是电话联系还是qq联系

    private String url_load;
    private View web_root;
    private TextView project_detail_remainder;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.sub_title_right_tv:
            ConstantDataUnit zhmmgl = getConstantDataByKey(Constants.dz_zhmmgl);
            if (zhmmgl != null) {
                Intent int1 = new Intent();
                int1.setClass(getContext(), WebViewPage.class).putExtra("title", zhmmgl.getName())
                    .putExtra("url", zhmmgl.getVal() + "?token=" + getToken());
                startNewActivity(int1, R.anim.push_left_in, R.anim.push_left_out, false);
            }
            break;
        case R.id.sub_title_right_bt:
            //分享
            if (mSharePre != null) {
                String title = mSharePre.getTitle();
                String content = mSharePre.getContent();
                String url = mSharePre.getUrl();
                String pic = mSharePre.getPic();
                UmShearUtils.shear(WebViewPage.this, url, true, title, content, pic);
            }
            break;
        case R.id.sub_title_left_ll:
            onBackPress();
            break;
        case R.id.to_inverst: //项目详情页可投资按钮
            if (ViewUtils.isFastDoubleClick(view)) {
                return;
            }
            if (projectDetail != null && tiger_host == null) { //直投或者转让项目 的页面点击事件
                //直投
                if (projectDetail instanceof ProjectdetailData) {
                    if (((ProjectdetailData) projectDetail).getStatus() != Constants.PRO_STATUS_TRADING) {
                        return;
                    }
                    if (!isLogin()) {
                        Intent intent = new Intent(WebViewPage.this, LoginPage.class).putExtra(
                            "FROM", R.id.to_inverst);
                        startNewActivity(intent, R.anim.slide_in_from_bottom, R.anim.silent_anim,
                            false);
                        return;
                    }
                    if (!hasOpenThirdAct()) {
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "",
                            "您还未开通汇付天下托管账号，继续开通", "取消", "继续", true, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {

                                }

                                @Override
                                public void onClickCancel() {
                                    // 确认，则继续
                                    openpayment();
                                }
                            });
                        return;
                    }
                    if (((ProjectdetailData) projectDetail).getAmount() != 0) {

                        Order order = createOrder(((ProjectdetailData) projectDetail));
                        Intent intent = new Intent(mContext, InverstInputAmountPage.class)
                            .putExtra("ORDER", order);
                        startNewActivityforresult(intent, R.anim.slide_in_from_bottom,
                            R.anim.silent_anim, ProjectDetailPage.TENDERREQUEST);
                    }
                }
                //转让
                if (projectDetail instanceof DebtProjectdetailData) {
                    if (((DebtProjectdetailData) projectDetail).getStatus() != 1) {
                        return;
                    }
                    if (!isLogin()) {
                        Intent intent = new Intent(WebViewPage.this, LoginPage.class).putExtra(
                            "FROM", R.id.to_inverst);
                        startNewActivity(intent, R.anim.slide_in_from_bottom, R.anim.silent_anim,
                            false);
                        return;
                    }
                    if (!hasOpenThirdAct()) {
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "",
                            "您还未开通汇付天下托管账号，继续开通", "取消", "继续", true, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {

                                }

                                @Override
                                public void onClickCancel() {
                                    // 确认，则继续
                                    openpayment();
                                }
                            });
                        return;
                    }

                    if (0 == ((DebtProjectdetailData) projectDetail).getInvestMark()) {
                        showToast("当前投资转让是您发起的，不可进行投资");
                        return;
                    }
                    Intent intent = new Intent(mContext, DebtInverstInputAmountPage.class)
                        .putExtra("ORDER", (DebtProjectdetailData) projectDetail);
                    startNewActivity(intent, R.anim.slide_in_from_bottom, R.anim.silent_anim, false);

                }
            } else if (projectDetail == null && tiger_host != null) { //活期的页面点击事件
                if (!isLogin()) {
                    Intent intent = new Intent(WebViewPage.this, LoginPage.class).putExtra("FROM",
                        R.id.to_inverst);
                    startNewActivity(intent, R.anim.slide_in_from_bottom, R.anim.silent_anim, false);
                    return;
                }
                if (!TwoTigerApp.getInstance().getUser().hasOpenThirdAct) {
                    PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "",
                        "您还未开通汇付天下托管账号，继续开通", "取消", "继续", true, new ReChargeClickListener() {

                            @Override
                            public void onClickConfirm() {

                            }

                            @Override
                            public void onClickCancel() {
                                openpayment();
                            }
                        });

                    return;
                }
                if (TwoTigerApp.getInstance().getUser().hasOpenProjectXAct) {
                    getCurrentProject();
                } else {
                    PromptManager.showCurrentAlertHasBtn(WebViewPage.this, "",
                        "参与老虎活期，需要您授权开通账户自动投资功能。\n自动投资将仅用于活期每日复投，不会影响到其他资金。", "立即开通", false,
                        new ReChargeClickListener() {

                            @Override
                            public void onClickConfirm() {
                                openAutoCurrentProject();
                            }

                            @Override
                            public void onClickCancel() {

                            }
                        });
                }
            }

            break;
        default:
            break;
        }
    }

    private void getCurrentProject() {
        params.clear();
        params.put("token", getToken());
        getDate(params, Constants.PROJECTXQUERY, handler, GETCURRENTPROJECTSUCCES,
            GETCURRENTPROJECTFAIL, true, false, false);
    }

    private void openAutoCurrentProject() {
        params.clear();
        params.put("token", getToken());
        getDate(params, Constants.PROJECTXOPEN, handler, OPENAUTOCURRENTPROJECTSUCCES,
            OPENAUTOCURRENTPROJECTFAIL, true, false, false);
    }

    /**
     * 开通三方
     */
    public void openpayment() {
        params.clear();
        params.put("token", getToken());
        getDate(params, Constants.REGISTHF, handler, OPENPAYMENTSUCCES, OPENPAYMENTFAIL, true,
            true, false);
    }

    @Override
    protected void onActivityResult(int requestcode, int resultcode, Intent intent) {
        super.onActivityResult(requestcode, resultcode, intent);
        if (requestcode == ProjectDetailPage.TENDERREQUEST) {
            if (resultcode == ProjectDetailPage.TENDERRESULTCLOSE_SUC) {
                setResult(ProjectDetailPage.TENDERRESULTCLOSE_SUC);
                finish();
            } else if (resultcode == ProjectDetailPage.TENDERRESULTCLOSE_FAI) {
                setResult(ProjectDetailPage.TENDERRESULTCLOSE_FAI);
                finish();
            }
        } else if (requestcode == CurrentHost.CURRENTREQUEST) {
            if (resultcode == CurrentHost.CURRENTRESULTCLOSE_SUC) {
                setResult(CurrentHost.CURRENTRESULTCLOSE_SUC);
                finish();
            } else if (resultcode == CurrentHost.CURRENTRESULTCLOSE_FAI) {
                setResult(CurrentHost.CURRENTRESULTCLOSE_FAI);
                finish();
            }
        }
    }

    @Override
    protected void onRestart() {
        //先判断是否需要重新加载页面  
        if (application.isNeedReload()) {
            if (!StringUtils.isEmpty(url_load)) {
                Map<String, String> extraHeaders = new HashMap<String, String>();
                if (!TextUtils.isEmpty(getToken())) {
                    extraHeaders.put("Token", getToken());
                } else {
                    extraHeaders.put("Token", "");
                }
                mWebView.loadUrl(url_load, extraHeaders); //将token信息放到header中
            }
            application.setNeedReload(false);
        }
        super.onRestart();
    }

    @Override
    protected void setListener() {
        handler = new BaseHandler(this) {

            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case GETCONTACTSUCCESS:
                    Contact mContact = JSONObject.parseObject((String) msg.obj, Contact.class);
                    if (mContact.isOk()) {
                        if (TAG_CLICK_TELE.equals(tag_click)) {
                            String telNum = mContact.getTelNum();
                            IntentUtil.CallPhone(WebViewPage.this, telNum);
                        } else if (TAG_CLICK_QQ.equals(tag_click)) {
                            String qqServUrl = mContact.getQqServUrl();
                            String qqType = mContact.getQqType();

                            if ("personal".equals(qqType)) { //需根据时间弹窗
                                String timeNow = TimeUtils.getFormatTime1();
                                String qqServTime = mContact.getQqServTime();
                                String[] timeArray = qqServTime.split("-");
                                int nowTimeToMinute = TimeUtils.timeToMinute(timeNow);
                                int qqServTimePreToMinute = TimeUtils.timeToMinute(timeArray[0]);
                                int qqServTimeEndToMinute = TimeUtils.timeToMinute(timeArray[1]);
                                if (nowTimeToMinute < qqServTimePreToMinute
                                    || nowTimeToMinute > qqServTimeEndToMinute) {
                                    PromptManager.showContactAlert(WebViewPage.this,
                                        "工作时间：" + qqServTime + "\n请在工作时间联系哦", "我知道了", "",
                                        new ClickListener() {

                                            @Override
                                            public void onClickRight() {
                                            }

                                            @Override
                                            public void onClickLeft() {
                                            }
                                        }, false);
                                } else {
                                    Intent intent = new Intent(Intent.ACTION_VIEW,
                                        Uri.parse(qqServUrl));
                                    if (IntentUtil.queryIntentActivities(WebViewPage.this, intent)) {
                                        startNewActivity(intent, R.anim.push_left_in,
                                            R.anim.push_left_out, false);
                                    } else {
                                        showToast("您的手机还未安装QQ,请先下载QQ");
                                    }
                                }
                            } else { //直接进入聊天，无需再根据时间判断是否弹窗
                                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(qqServUrl));
                                if (IntentUtil.queryIntentActivities(WebViewPage.this, intent)) {
                                    startNewActivity(intent, R.anim.push_left_in,
                                        R.anim.push_left_out, false);
                                } else {
                                    showToast("您的手机还未安装QQ,请先下载QQ");
                                }
                            }
                        }
                    } else {
                        showToast(mContact.codeDesc);
                    }
                    break;
                case GETCONTACTFAILURE:
                    showToast("网络异常");
                    break;
                case OPENAUTOCURRENTPROJECTSUCCES:
                    Basebean result = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result.isOk()) {
                        BroswerUrl mBroswerUrl = JSONObject.parseObject(result.data,
                            BroswerUrl.class);
                        Intent intent = new Intent(WebViewPage.this, WebViewPage.class);
                        intent.putExtra("title", "账户自动投资");
                        intent.putExtra("url", mBroswerUrl.getUrl());
                        intent.putExtra("BUSINESS_TYPE", WebViewPage.TYPE_OPEN_AUTO_PROJECT);
                        startNewActivity(intent, R.anim.push_left_in, R.anim.push_left_out, false);
                    } else {
                        showToast(result.codeDesc);
                    }
                    break;
                case OPENAUTOCURRENTPROJECTFAIL:
                    showToast("网络异常");
                    break;
                case GETCURRENTPROJECTSUCCES:
                    Basebean result_1 = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result_1.isOk()) {
                        CurrentProject mCurrentProject = JSONObject.parseObject(result_1.data,
                            CurrentProject.class);
                        Intent intent2 = new Intent(WebViewPage.this, CurrentInputAmountPage.class);
                        intent2.putExtra("CURRENTPROJECT", mCurrentProject);
                        startNewActivityforresult(intent2, R.anim.slide_in_from_bottom,
                            R.anim.silent_anim, CurrentHost.CURRENTREQUEST);
                    } else {
                        showToast(result_1.codeDesc);
                    }
                    break;
                case GETCURRENTPROJECTFAIL:
                    showToast("网络异常");
                    break;
                case TO_SHARE_CHANNEL:
                    Share share = (Share) msg.obj;
                    UmShearUtils.shear(WebViewPage.this, share, true);
                    break;
                case TO_SHARE:
                    Share mShare = (Share) msg.obj;
                    String title = mShare.getTitle();
                    String content = mShare.getContent();
                    String url = mShare.getUrl();
                    String pic = mShare.getPic();
                    UmShearUtils.shear(WebViewPage.this, url, true, title, content, pic);
                    break;
                case TO_SHARE_PRE:
                    mSharePre = (Share) msg.obj;
                    break;
                case TO_CHANGE_COUPON: //js兑换优惠券
                    String caId = (String) msg.obj;
                    params.clear();
                    params.put("caId", caId);
                    params.put("token", getToken());
                    getDate(params, Constants.coupon_exchange, handler, EXCHANGECOUPONSUCCES,
                        EXCHANGECOUPONFAIL, true, false, false);
                    break;
                case TO_SYSBROWSER:
                    String toSysbrowserUrl = (String) msg.obj;
                    IntentUtil.openUrlBySysBrowser(WebViewPage.this, toSysbrowserUrl);
                    break;
                case EXCHANGECOUPONSUCCES:
                    Basebean baseBean = JSON.parseObject((String) msg.obj, Basebean.class);
                    if (baseBean.isOk()) {
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "兑换成功", "", "确定",
                            "", false, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                    if (!StringUtils.isEmpty(url_load)) {
                                        mWebView.loadUrl(url_load);
                                    }
                                }

                                @Override
                                public void onClickCancel() {

                                }
                            });
                    } else {
                        showToast(baseBean.codeDesc);
                    }
                    break;
                case EXCHANGECOUPONFAIL:
                    showToast("网络异常");
                    break;
                case GOTO_BOUTIQUEPAGE: //js调用跳精选页
                    startNewActivity(new Intent(WebViewPage.this, HomeActivity.class).putExtra(
                        "BUTTON", R.id.radio_btn1), R.anim.push_left_in, R.anim.push_left_out, true);
                    break;
                case GOTO_PROJECTEPAGE: //js调用跳列表
                    startNewActivity(new Intent(WebViewPage.this, HomeActivity.class).putExtra(
                        "BUTTON", R.id.radio_btn2), R.anim.push_left_in, R.anim.push_left_out, true);
                    break;
                case GOTO_ACCOUNTEPAGE: //js调用跳我的钱页
                    startNewActivity(new Intent(WebViewPage.this, HomeActivity.class).putExtra(
                        "BUTTON", R.id.radio_btn4), R.anim.push_left_in, R.anim.push_left_out, true);
                    break;
                case GOTO_MOREPAGE: //js调用跳更多页
                    startNewActivity(new Intent(WebViewPage.this, MorePage.class),
                        R.anim.push_left_in, R.anim.push_left_out, false);
                    break;
                case GOTO_CURRENTPAGE: //js调用跳活期页
                    startNewActivity(new Intent(WebViewPage.this, HomeActivity.class).putExtra(
                        "BUTTON", R.id.radio_btn3), R.anim.push_left_in, R.anim.push_left_out, true);
                    break;
                case GOTO_PROJECTEPAGE_TRANS: //js调用跳列表--转让页
                    startNewActivity(new Intent(WebViewPage.this, HomeActivity.class).putExtra(
                        "BUTTON", R.id.radio_btn2), R.anim.push_left_in, R.anim.push_left_out, true);
                    //在全局中设置标志，表示进入列表页之后显示转让列表
                    application.setWitchTag(Projectpage.WITCH_TIGER_DEBT);
                    break;
                case GOTO_CURRENT_ENTER: //js调用跳活期转入页面
                    if (!isLogin()) {
                        Intent intent = new Intent(WebViewPage.this, LoginPage.class).putExtra(
                            "FROM", R.id.to_inverst);
                        startNewActivity(intent, R.anim.slide_in_from_bottom, R.anim.silent_anim,
                            false);
                        return;
                    }
                    if (!TwoTigerApp.getInstance().getUser().hasOpenThirdAct) {
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "",
                            "您还未开通汇付天下托管账号，继续开通", "取消", "继续", true, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {

                                }

                                @Override
                                public void onClickCancel() {
                                    openpayment();
                                }
                            });

                        return;
                    }
                    if (TwoTigerApp.getInstance().getUser().hasOpenProjectXAct) {
                        getCurrentProject();
                    } else {
                        PromptManager.showCurrentAlertHasBtn(WebViewPage.this, "",
                            "参与老虎活期，需要您授权开通账户自动投资功能。\n自动投资将仅用于活期每日复投，不会影响到其他资金。", "立即开通", false,
                            new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                    openAutoCurrentProject();
                                }

                                @Override
                                public void onClickCancel() {

                                }
                            });
                    }
                    break;
                case GOTO_CHATPAGE://js调用跳在线客服页面
                    new EaseHXUtils().startEaseChat(mContext);
                    break;
                case GET_USERINFO_SSUCESS:
                    Basebean result_2 = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result_2.isOk()) {
                        User user = JSON.parseObject(result_2.data, User.class);
                        if (user.hasOpenThirdAct) {
                            application.setUser(user);
                            showDialogPaymentRegistSuccess("开通成功");
                        } else {
                            showDialogPaymentRegistFailure(msg_url);
                        }
                    }
                    break;
                case GET_USERINFO_FAIL:

                    break;
                case OPENPAYMENTSUCCES:
                    Basebean result_open = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result_open.isOk()) {
                        BroswerUrl responseinfo = JSONObject.parseObject(result_open.data,
                            BroswerUrl.class);
                        Intent intent = new Intent(WebViewPage.this, WebViewPage.class);
                        intent.putExtra("title", "开通三方托管账户");
                        intent.putExtra("url", responseinfo.getUrl());
                        intent.putExtra("BUSINESS_TYPE", WebViewPage.TYPE_PAYMENT_REGIST);
                        startNewActivity(intent, R.anim.push_left_in, R.anim.push_left_out,
                            isFinish);
                    } else {
                        showToast(result_open.codeDesc);
                    }
                    break;
                case OPENPAYMENTFAIL:
                    showToast("网络异常");
                    break;
                case GETASSERTSUCCES:
                    User userInfo = JSON.parseObject((String) msg.obj, User.class);
                    if (userInfo.isOk()) {
                        application.setUser(userInfo);
                        finish();
                        overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
                    } else {
                        showToast(userInfo.codeDesc);
                    }
                    break;
                case GETASSERTFAIL:
                    showToast("网络异常");
                    break;
                case LOOPGETUSERBANKCARD:
                    getuserbankcards();
                    break;
                case GETBANKSUCCES: //银行卡列表请求成功
                    Basebean result_4 = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result_4.isOk()) {
                        WithdrawBank withdrawBank = JSON.parseObject(result_4.data,
                            WithdrawBank.class);
                        List<CashBank> listBank = JSON.parseArray(withdrawBank.getBankList(),
                            CashBank.class);
                        if (!ListUtils.isEmpty(listBank)) {
                            if (CashPage.CHECKBYQUICKBANK.equals(check_tag)) {
                                application.setCashBanks(listBank);
                                if (application.getLLCashBank() == null) { //连连卡为空。说明绑卡已经把这张连连卡绑成了汇付卡
                                    showMyDialog();
                                } else {
                                    handler.sendEmptyMessageDelayed(LOOPGETUSERBANKCARD, 3000);
                                }
                            } else {
                                List<CashBank> oldUserBanks = application.getcashBanks();
                                application.setCashBanks(listBank);
                                List<CashBank> newUserBanks = application.getcashBanks();
                                if (ListUtils.isEmpty(oldUserBanks)) {
                                    showMyDialog();
                                } else {
                                    if (newUserBanks.size() > oldUserBanks.size()) { //说明是在添加银行卡
                                        showMyDialog();
                                    } else {
                                        handler.sendEmptyMessageDelayed(LOOPGETUSERBANKCARD, 3000);
                                    }
                                }
                            }
                        } else { //银行卡列表为空，说明还没有绑定成功。继续发送定时任务
                            handler.sendEmptyMessageDelayed(LOOPGETUSERBANKCARD, 3000);
                        }
                    } else { //请求错误，也得继续发送定时任务
                        handler.sendEmptyMessageDelayed(LOOPGETUSERBANKCARD, 3000);
                    }
                    break;
                case GETBANKFAIL://银行卡列表请求失败（网络超时等...）
                    handler.sendEmptyMessageDelayed(LOOPGETUSERBANKCARD, 3000);
                    break;
                case GETDEBTDETAILSUCCES:
                    Basebean result_debt = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result_debt.isOk()) {
                        DebtProjectdetailData mDebtProjectdetailData = JSON.parseObject(
                            result_debt.data, DebtProjectdetailData.class);
                        if (mDebtProjectdetailData.getStatus() != 1) {
                            return;
                        }
                        if (!isLogin()) {
                            Intent intent = new Intent(WebViewPage.this, LoginPage.class).putExtra(
                                "FROM", R.id.to_inverst);
                            startNewActivity(intent, R.anim.slide_in_from_bottom,
                                R.anim.silent_anim, false);
                            return;
                        }
                        if (!hasOpenThirdAct()) {
                            PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "",
                                "您还未开通汇付天下托管账号，继续开通", "取消", "继续", true,
                                new ReChargeClickListener() {

                                    @Override
                                    public void onClickConfirm() {

                                    }

                                    @Override
                                    public void onClickCancel() {
                                        // 确认，则继续
                                        openpayment();
                                    }
                                });
                            return;
                        }

                        if (0 == mDebtProjectdetailData.getInvestMark()) {
                            showToast("当前投资转让是您发起的，不可进行投资");
                            return;
                        }
                        Intent intent = new Intent(mContext, DebtInverstInputAmountPage.class)
                            .putExtra("ORDER", mDebtProjectdetailData);
                        startNewActivity(intent, R.anim.slide_in_from_bottom, R.anim.silent_anim,
                            false);
                    } else {
                        showToast(result_debt.codeDesc);
                    }
                    break;
                case GETDEBTDETAILFAIL:
                    showToast("网络异常");
                    break;
                case GETDETAILSUCCES:
                    Basebean result_3 = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result_3.isOk()) {
                        ProjectdetailData proData = JSON.parseObject(result_3.data,
                            ProjectdetailData.class);
                        if (Constants.TYPE_NID_ZHITOU.equals(proData.getType())) { //直投类型需跳到直投的投资页面
                            if (proData.getStatus() != Constants.PRO_STATUS_TRADING) { //项目不是募集中则  不能投资则跳到详情页面
                                Intent intent = new Intent(WebViewPage.this,
                                    ProjectDetailPage.class).putExtra("PROJECT_ID",
                                    proData.getProjectId()).putExtra("MODE", proData.getMode());
                                startNewActivity(intent, R.anim.push_left_in, R.anim.push_left_out,
                                    false);
                                return;
                            }
                            if (!isLogin()) {
                                Intent intent = new Intent(WebViewPage.this, LoginPage.class)
                                    .putExtra("FROM", R.id.to_inverst);
                                startNewActivity(intent, R.anim.slide_in_from_bottom,
                                    R.anim.silent_anim, false);
                                return;
                            }
                            if (!hasOpenThirdAct()) {
                                PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "",
                                    "您还未开通汇付天下托管账号，继续开通", "取消", "继续", true,
                                    new ReChargeClickListener() {

                                        @Override
                                        public void onClickConfirm() {

                                        }

                                        @Override
                                        public void onClickCancel() {
                                            // 确认，则继续
                                            openpayment();
                                        }
                                    });
                                return;
                            }
                            if (Constants.PRO_TYPE_NEWER.equals(proData.getMode())) { //新手项目老手不能进入投资页，只能看详情
                                if (!isNewMan()) {
                                    showToast("新手项目仅限第一次投资");
                                    return;
                                }
                            }
                            if (proData.getAmount() != 0) {

                                Order order = createOrder(proData);

                                Intent intent = new Intent(mContext, InverstInputAmountPage.class)
                                    .putExtra("ORDER", order);
                                startNewActivity(intent, R.anim.slide_in_from_bottom,
                                    R.anim.silent_anim, false);

                            }
                        } else if (Constants.TYPE_NID_HEIDONG.equals(proData.getType())) { //黑洞类型需跳到黑洞的投资页面
                            if (!isLogin()) {
                                Intent intent = new Intent(WebViewPage.this, LoginPage.class)
                                    .putExtra("FROM", R.id.to_inverst);
                                startNewActivity(intent, R.anim.slide_in_from_bottom,
                                    R.anim.silent_anim, false);
                                return;
                            }
                            if (!hasOpenThirdAct()) {
                                PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "",
                                    "您还未开通汇付天下托管账号，继续开通", "取消", "继续", true,
                                    new ReChargeClickListener() {

                                        @Override
                                        public void onClickConfirm() {

                                        }

                                        @Override
                                        public void onClickCancel() {
                                            // 确认，则继续
                                            openpayment();
                                        }
                                    });
                                return;
                            }
                            if (!isNewManForWYTYJ()) {
                                showToast("体验金项目仅限未投资用户参与");
                                return;
                            }

                            //进入投资确认页面，将订单信息传过去
                            ExperienceOrder mExperienceOrder = createExperienceOrder(proData);

                            Intent intent = new Intent(mContext, ExperienceInverstConfirmPage.class)
                                .putExtra("ORDER", mExperienceOrder);
                            startNewActivity(intent, R.anim.slide_in_from_bottom,
                                R.anim.silent_anim, false);
                        }
                    } else {
                        showToast(result_3.codeDesc);
                    }
                    break;
                case GETDETAILFAIL:
                    showToast("网络异常");
                    break;
                default:
                    break;
                }
                super.handleMessage(msg);
            }
        };
        sub_title_left_ll.setVisibility(View.VISIBLE);
        sub_title_left_ll.setOnClickListener(this);
        sub_title_right_bt.setOnClickListener(this);
        sub_title_right_tv.setOnClickListener(this);
    }

    /**
     * 创建体验金订单类
     * 
     * @param proData
     */
    protected ExperienceOrder createExperienceOrder(ProjectdetailData proData) {
        ExperienceOrder mExperienceOrder = new ExperienceOrder();
        mExperienceOrder.setProjectid(proData.getProjectId());
        mExperienceOrder.setProjectname(proData.getName());
        mExperienceOrder.setProject_yield(proData.getYield());
        mExperienceOrder.setRecyle(proData.getPeriod());
        mExperienceOrder.setRepaymenttype(proData.getRepayTypeName());
        mExperienceOrder.setStartyidtime(proData.getStartInterestDate()); //起息时间
        mExperienceOrder.setStartrepytime(proData.getEndInterestDate()); //还款时间
        mExperienceOrder.setMinInvest(proData.getMinInvest());
        mExperienceOrder.setMaxInvest(proData.getMaxInvest());
        mExperienceOrder.setInverstamount(proData.getValuation());

        mExperienceOrder.setType(proData.getType());
        mExperienceOrder.setMode(proData.getMode());

        mExperienceOrder.setRepayAmount(proData.getRepayAmount()); //用户实付金额

        return mExperienceOrder;
    }

    /**
     * 创建订单类
     * 
     * @param proData
     * @return
     */
    protected Order createOrder(ProjectdetailData proData) {

        Order order = new Order();
        order.setProjectid(proData.getProjectId());
        order.setProjectname(proData.getName());
        order.setProject_yield(proData.getYield() + proData.getAwardYield());
        order.setRecyle(proData.getPeriod());
        order.setRepaymenttype(proData.getRepayTypeName());
        order.setStartrepytime(proData.getEndInterestDate());
        order.setStartyidtime(proData.getStartInterestDate());
        order.setCaninverst(Double.parseDouble(proData.getRemainAmount()));
        order.setpType(proData.getpType());
        order.setMinInvest(proData.getMinInvest());
        order.setMaxInvest(proData.getMaxInvest());
        order.setType(proData.getType());
        order.setMode(proData.getMode());
        return order;
    }

    /**
     * 绑卡成功的弹窗
     */
    public void showMyDialog() {
        PromptManager.showAlertCommon(WebViewPage.this, 0, "绑卡成功", "您可以去提现了~", "", "", "去提现",
            false, false, false, new ReChargeClickListener() {

                @Override
                public void onClickConfirm() {

                }

                @Override
                public void onClickCancel() {
                    setResult(CashPage.BINGCARDRESULTCLOSE_SUC);
                    finish();
                }
            }, new ContactClick());

    }

    /**
     * 开通第三方汇付成功弹窗
     */
    private void showDialogPaymentRegistSuccess(String msg) {
        PromptManager.showAlertCommon(WebViewPage.this, 0, msg, "", "", "先逛逛", "去看看", true, false,
            false, new ReChargeClickListener() {

                @Override
                public void onClickConfirm() {
                    //返回到之前的界面
                    finish();
                }

                @Override
                public void onClickCancel() {
                    finish();
                }
            }, new ContactClick());

    }

    /**
     * 开通第三方汇付失败弹窗
     */
    private void showDialogPaymentRegistFailure(String msg) {
        PromptManager.showAlertCommon(WebViewPage.this, 0, "开通失败", "失败原因：" + msg, "", "", "再试一次",
            false, false, true, new ReChargeClickListener() {

                @Override
                public void onClickConfirm() {

                }

                @Override
                public void onClickCancel() {
                    finish();
                }
            }, new ContactClick());
    }

    /**
     * 获取银行卡列表
     */
    private void getuserbankcards() {
        params.clear();
        params.put("token", getToken());
        params.put("type", "withdraw");
        getDate(params, Constants.WITHDRAWBANKQUERY, handler, GETBANKSUCCES, GETBANKFAIL, false,
            true, false);
    }

    @SuppressWarnings("deprecation")
    @SuppressLint("SetJavaScriptEnabled")
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    protected void processLogic() {
        errorHtml = "<html><body><h1>Page not find!</h1><h2>load failure</h2></body></html>";
        params = getParm();
        isFinish = false;
        try {
            if (mWebView != null) {
                mWebView.setWebViewClient(new NewsClient());

                url_load = getIntent().getStringExtra("url");
                String titleText = getIntent().getStringExtra("title");
                String str = getIntent().getStringExtra("isBindCard");
                check_tag = getIntent().getStringExtra("check_tag"); //绑卡成功与否 的判断规则
                projectDetail = (Basebean) getIntent().getSerializableExtra("PROJECTDETAIL");
                tiger_host = getIntent().getStringExtra("TIGER_HOST"); //判断是否是老虎活期的介绍页面，并显示立即转入的按钮
                String str_right_tv = getIntent().getStringExtra("SHOWPASSWORD"); //是否显示右上角的文字（找回密码）
                business_type = getIntent().getStringExtra("BUSINESS_TYPE");//业务类型
                back_mode = getIntent().getStringExtra("BACK_MODE"); //点击左上角的箭头 是直接退出webviewpage还是web页面一步一步返回

                //开通自动投资类型的 需要显示“找回密码”，左上角是x号
                if (TYPE_OPEN_AUTO_PROJECT.equals(business_type)) {
                    sub_title_right_tv.setText("找回密码");
                    sub_title_right_tv.setVisibility(View.VISIBLE);
                    sub_title_left_bt.setImageDrawable(this.getResources().getDrawable(
                        R.drawable.leftback));
                }

                //判断右上角的文字显示
                if ("showPassword".equals(str_right_tv)) {
                    sub_title_right_tv.setText("找回密码");
                    sub_title_right_tv.setVisibility(View.VISIBLE);
                } else {
                    sub_title_right_tv.setVisibility(View.GONE);
                }

                if (projectDetail != null && tiger_host == null) { //需要显示按钮，按钮根据状态有不同的显示
                    initButton();
                } else if (projectDetail == null && tiger_host != null) {
                    initButtonOfHost();
                }
                if (CashPage.BINDCARD.equals(str)) { //绑定银行卡标示
                    //开启定时请求银行卡列表。一旦请求结果银行卡列表不为0则表示绑卡成功。这时候就可以弹窗提示了
                    startToLoopGetUserBankCards();
                }
                sub_title_center_tv.setText("");
                LogUtil.info("url" + url_load);
                LogUtil.info("title" + titleText);
                if (StringUtils.isEmpty(url_load)) {
                    url_load = "http://www.twotiger.com";
                }
                //                mWebView.loadUrl("file:///android_asset/test.html"); 
                Map<String, String> extraHeaders = new HashMap<String, String>();
                if (!TextUtils.isEmpty(getToken())) {
                    extraHeaders.put("Token", getToken());
                } else {
                    extraHeaders.put("Token", "");
                }
                mWebView.loadUrl(url_load, extraHeaders);
                WebSettings mWebSettings = mWebView.getSettings();
                mWebSettings.setJavaScriptEnabled(true);
                String appCachePath = getCacheDir().getAbsolutePath();
                mWebSettings.setAppCacheEnabled(true);
                mWebSettings.setDefaultTextEncodingName("UTF-8");
                mWebSettings.setAppCachePath(appCachePath);
                mWebSettings.setAppCacheMaxSize(8 * 1024 * 1024);
                mWebSettings.setAllowFileAccess(true);
                mWebSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    mWebSettings.setDisplayZoomControls(false);
                } else {

                }
                mWebSettings.setBuiltInZoomControls(false);
                mWebSettings.setUseWideViewPort(false);
                mWebSettings.setLoadWithOverviewMode(true);
                mWebSettings.setSupportZoom(true);
                String ua = Tools.getUserAgent(mContext);
                LogUtil.info("useragent: " + ua);
                mWebSettings.setUserAgentString(ua);
                MyWebChromeClient myWebChromeClient = new MyWebChromeClient();
                new MobclickAgentJSInterface(this, mWebView, myWebChromeClient);
                mWebView.setWebChromeClient(myWebChromeClient);

                mWebView.addJavascriptInterface(new JavaScriptInterface(mWebView, WebViewPage.this,
                    handler), JavaScriptInterface.name());

                mWebView.setOnTouchListener(new View.OnTouchListener() {
                    @SuppressLint("ClickableViewAccessibility")
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                        case MotionEvent.ACTION_UP:
                            if (!v.hasFocus()) {
                                v.requestFocus();
                            }
                            break;
                        }
                        return false;
                    }
                });

                mWebView.setOnLongClickListener(new OnLongClickListener() {

                    @Override
                    public boolean onLongClick(View v) {
                        return true;
                    }
                });

            } else {

            }

        } catch (Exception e) {
            LogUtil.info(String.valueOf(e.getMessage()));
        }
    }

    private void initButtonOfHost() {
        ll_bottom.setVisibility(View.VISIBLE);
        project_detail_remainder.setVisibility(View.GONE);
        to_inverst.setText("立即转入");
    }

    private void initButton() {
        ll_bottom.setVisibility(View.VISIBLE);
        if (projectDetail instanceof ProjectdetailData) { //直投

            project_detail_remainder
                .setText("剩余可投："
                         + ArithUtils.coverMoneyComma(("" + ((ProjectdetailData) projectDetail)
                             .getRemainAmount())));

            //立即投资按钮
            if (((ProjectdetailData) projectDetail).getStatus() == Constants.PRO_STATUS_WAITING) {//倒计时
                //                projectCommingJob = new ProjectCommingJob();
                //                projectCommingJob.start();
                to_inverst.setText("未开始");
                to_inverst.setBackgroundResource(R.color.gray_1);
            } else if (((ProjectdetailData) projectDetail).getStatus() != Constants.PRO_STATUS_TRADING) {
                to_inverst.setText(((ProjectdetailData) projectDetail).getStatusName());
                to_inverst.setBackgroundResource(R.color.gray_1);
            }
            if (Constants.PRO_TYPE_NEWER.equals(((ProjectdetailData) projectDetail).getMode())) {
                if (isNewMan()) {
                    to_inverst.setText("立即投资");
                    to_inverst.setBackgroundResource(R.color.orange);
                    to_inverst.setClickable(true);
                } else {
                    to_inverst.setText("仅限新手");
                    to_inverst.setBackgroundResource(R.color.gray_1);
                    to_inverst.setClickable(false);
                }
            }
        }
        if (projectDetail instanceof DebtProjectdetailData) { //转让

            project_detail_remainder
                .setText("剩余可投："
                         + ArithUtils.coverMoneyComma(("" + ((DebtProjectdetailData) projectDetail)
                             .getRemainAmount())));

            //立即投资按钮
            if (((DebtProjectdetailData) projectDetail).getStatus() == 1) {//立即认购
                to_inverst.setText("立即购买");
            } else if (((DebtProjectdetailData) projectDetail).getStatus() == 2) { //还款中
                to_inverst.setText(((DebtProjectdetailData) projectDetail).getStatusName());
                to_inverst.setBackgroundResource(R.color.gray_1);
            } else if (((DebtProjectdetailData) projectDetail).getStatus() == 3) { //已完成
                to_inverst.setText(((DebtProjectdetailData) projectDetail).getStatusName());
                to_inverst.setBackgroundResource(R.color.gray_1);
            }
        }
    }

    //    class ProjectCommingJob implements Runnable {
    //
    //        /**每个县城只能start一次*/
    //        private boolean isRun = false;
    //        private boolean stop = false;
    //
    //        public void stop() {
    //            this.stop = true;
    //        }
    //
    //        public void start() {
    //            if (isRun)
    //                return;
    //            isRun = true;
    //            stop = false;
    //            handler.post(this);
    //        }
    //
    //        @Override
    //        public void run() {
    //            LogUtil.info(ProjectCommingJob.class, "project: " + projectDetail.getTime2Start());
    //            to_inverst.setText("倒计时 : " + projectDetail.getTime2Start());
    //            if (stop) {
    //                return;
    //            }
    //            if (projectDetail.getStatus() == Constants.PRO_STATUS_WAITING) {
    //                handler.postDelayed(this, 1000);
    //            }
    //        }
    //    }

    private void startToLoopGetUserBankCards() {
        handler.sendEmptyMessageDelayed(LOOPGETUSERBANKCARD, 3000);

    }

    @Override
    public void onPause() {
        super.onPause();
        //SDK已经禁用了基于Activity 的页面统计，所以需要再次重新统计页面
        MobclickAgent.onPageEnd(mPageName);
        MobclickAgent.onPause(this);
        //        if (projectCommingJob != null) {
        //            projectCommingJob.stop();
        //        }
    }

    @Override
    public void onResume() {
        super.onResume();
        //SDK已经禁用了基于Activity 的页面统计，所以需要再次重新统计页面
        MobclickAgent.onPageStart(mPageName);
        MobclickAgent.onResume(this);
        //        if (projectCommingJob != null) {
        //            projectCommingJob = new ProjectCommingJob();
        //            projectCommingJob.start();
        //        }
    }

    /**
     * 开通三方：openPayment
     * <p>
     * 投资接口：invest
     * <p>
     * 充值接口：recharge
     * <p>
     * 绑定银行卡：bindBankCard
     * <p>
     * 提现接口：cash
     */
    class NewsClient extends WebViewClient {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            LogUtil.info(WebViewPage.class, "页面开始的地址" + url);
            //先判断键盘是否开启，如果开启则收起键盘
            if (KeyboradListener.isshow(web_root)) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
                }
            }
            try {
                String isShowShare = URLUtil.getParam(url, "share", "no");
                if ("yes".equals(isShowShare)) {
                    sub_title_right_bt.setImageResource(R.drawable.page_share);
                    sub_title_right_bt.setVisibility(View.VISIBLE);
                } else {
                    sub_title_right_bt.setVisibility(View.GONE);
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description,
                                    String failingUrl) {
            view.loadData(errorHtml, "text/html; charset=UTF-8", null);//load失败，默认load本地HTML页面
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, final String url) {
            try {

                int result_tag = URLUtil.getParam2Int(url, "tag", 5);
                //                String result_type = URLUtil.getParam(url, "type", "failure");
                msg_url = URLUtil.getParam(url, "msg", "0000");

                if (result_tag == 0) { //成功
                    //投资包括 直投、转让、黑洞等等，不再依赖服务端的result_type，而是客户端自己维护流程
                    if (TYPE_INVESTENDLESS.equals(business_type)) { //投资成功(万元体验金项目)
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, msg_url,
                            "明天即可查看收益", "继续投资", "查看已投项目", true, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                    //跳转到投资页面
                                    setResult(ProjectDetailPage.TENDERRESULTCLOSE_SUC);
                                    finish();
                                }

                                @Override
                                public void onClickCancel() {
                                    //跳转到查看资产页面
                                    setResult(ProjectDetailPage.TENDERRESULTCLOSE_SUC);
                                    Intent intent = new Intent();
                                    intent.setClass(WebViewPage.this, InverstedRecordPage.class);
                                    startNewActivity(intent, R.anim.push_left_in,
                                        R.anim.push_left_out, true);
                                }
                            });

                    } else if (TYPE_INVESTTENDER.equals(business_type)) { //投资成功(直投项目)

                        Intent intent = new Intent(mContext, InvestSuccessPage.class);
                        intent.putExtra("TITLE", "投资成功");
                        intent.putExtra("TYPE", InvestSuccessPage.TYPE_TENDER);
                        startNewActivityforresult(intent, R.anim.push_left_in,
                            R.anim.push_left_out, ProjectDetailPage.TENDERREQUEST);

                    } else if (TYPE_INVESTDEBT.equals(business_type)) { //投资成功(转让项目)
                        Intent intent = new Intent(mContext, InvestSuccessPage.class);
                        intent.putExtra("TITLE", "购买成功");
                        intent.putExtra("TYPE", InvestSuccessPage.TYPE_DEBT);
                        startNewActivityforresult(intent, R.anim.push_left_in,
                            R.anim.push_left_out, ProjectDetailPage.TENDERREQUEST);
                    } else if (TYPE_CASE.equals(business_type)) { //取现成功
                        PromptManager.showAlertCommon(WebViewPage.this, 0, msg_url, getIntent()
                            .getStringExtra("EXPECTTIME"), "", "", "确定", false, false, false,
                            new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {

                                }

                                @Override
                                public void onClickCancel() {
                                    //跳转到我的钱页面
                                    setResult(CashPage.CASHRESULTCLOSE_SUC);
                                    finish();
                                }
                            }, new ContactClick());
                    } else if (TYPE_PAYMENT_REGIST.equals(business_type)) { //开通汇付成功

                        application.getUser().setHasOpenThirdAct(true);
                        application.setUser(application.getUser());
                        showDialogPaymentRegistSuccess(msg_url);

                    } else if (TYPE_RECHARGE_HF_DERECT.equals(business_type)) { //汇付充值成功----直接充值
                        PromptManager.showAlertCommon(WebViewPage.this, 0, msg_url, "任性投资去吧~", "",
                            "查看资产", "去投资", true, false, false, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                    //跳转到我的钱页面
                                    setResult(RechargePage.RECHARGERESULTCLOSE_SUC);
                                    finish();
                                }

                                @Override
                                public void onClickCancel() {
                                    startNewActivity(new Intent(WebViewPage.this,
                                        HomeActivity.class).putExtra("BUTTON", R.id.radio_btn2),
                                        R.anim.push_left_in, R.anim.push_left_out, true);
                                }
                            }, new ContactClick());
                    } else if (TYPE_RECHARGE_HF_ORDER.equals(business_type)) { //汇付充值成功----订单充值
                        PromptManager.showAlertCommon(WebViewPage.this, 0, msg_url, "还差最后一步即可投资成功",
                            "", "", "去投资", false, false, false, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                }

                                @Override
                                public void onClickCancel() {
                                    //跳转到我的钱页面
                                    setResult(RechargePage.RECHARGERESULTCLOSE_SUC);
                                    finish();
                                }
                            }, new ContactClick());

                    } else if (TYPE_OPEN_AUTO_PROJECT.equals(business_type)) { //开通自动投资成功
                        application.getUser().setHasOpenProjectXAct(true);
                        application.setUser(application.getUser());
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, msg_url,
                            "现在可以加入活期了~", "确定", "", false, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                    finish();
                                }

                                @Override
                                public void onClickCancel() {

                                }
                            });
                    }
                    return true;
                } else if (result_tag == 1) { //失败
                    if (TYPE_INVESTENDLESS.equals(business_type)) { //黑洞投资失败
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "", msg_url,
                            "确定", "", false, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                    setResult(ProjectDetailPage.TENDERRESULTCLOSE_FAI);
                                    finish();
                                }

                                @Override
                                public void onClickCancel() {

                                }
                            });
                    } else if (TYPE_INVESTTENDER.equals(business_type)) { //直投投资失败

                        Intent intent = new Intent(mContext, InvestFailurePage.class);
                        intent.putExtra("TITLE", "投资失败");
                        intent.putExtra("TYPE", InvestFailurePage.TYPE_TENDER);
                        intent.putExtra("MSG", msg_url);
                        startNewActivityforresult(intent, R.anim.push_left_in,
                            R.anim.push_left_out, ProjectDetailPage.TENDERREQUEST);

                    } else if (TYPE_INVESTDEBT.equals(business_type)) { //转让投资失败

                        Intent intent = new Intent(mContext, InvestFailurePage.class);
                        intent.putExtra("TITLE", "购买失败");
                        intent.putExtra("TYPE", InvestFailurePage.TYPE_DEBT);
                        intent.putExtra("MSG", msg_url);
                        startNewActivityforresult(intent, R.anim.push_left_in,
                            R.anim.push_left_out, ProjectDetailPage.TENDERREQUEST);

                    } else if (TYPE_CASE.equals(business_type)) { //取现失败
                        PromptManager.showAlertCommon(WebViewPage.this, 0, "提现失败", "失败原因："
                                                                                   + msg_url, "",
                            "", "再试一次", false, false, true, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {

                                }

                                @Override
                                public void onClickCancel() {
                                    //跳转到我的钱页面
                                    setResult(CashPage.CASHRESULTCLOSE_FAI);
                                    finish();
                                }
                            }, new ContactClick());
                    } else if (TYPE_PAYMENT_REGIST.equals(business_type)) { //开通汇付失败   由于这种情况有可能还是成功的，所以请求接口

                        getuserinfo();

                    } else if (TYPE_RECHARGE_HF_DERECT.equals(business_type)
                               || TYPE_RECHARGE_HF_ORDER.equals(business_type)) { //汇付充值失败 --直充或者订单充逻辑一样
                        PromptManager.showAlertCommon(WebViewPage.this, 0, "充值失败", "失败原因："
                                                                                   + msg_url, "",
                            "", "再试一次", false, false, true, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                }

                                @Override
                                public void onClickCancel() {
                                    //跳转到我的钱页面
                                    setResult(RechargePage.RECHARGESULTCLOSE_FAI);
                                    finish();
                                }
                            }, new ContactClick());
                    } else if (TYPE_OPEN_AUTO_PROJECT.equals(business_type)) { //开通自动投资失败
                        PromptManager.showConfirmAlertCommon(WebViewPage.this, 0, "", msg_url,
                            "确定", "", false, new ReChargeClickListener() {

                                @Override
                                public void onClickConfirm() {
                                    //跳转到我的钱页面
                                    finish();
                                }

                                @Override
                                public void onClickCancel() {

                                }
                            });
                    }
                    return true;
                }

            } catch (Exception e) {
                LogUtil.info(String.valueOf(e.getMessage()));
            }
            return false;
        }
    }

    /**
     * 获取客服电话和客服qq
     */
    protected void getContact() {
        //        params.clear();
        //        getDate(params, Constants.constant_query, handler, GETCONTACTSUCCESS, GETCONTACTFAILURE,
        //            true, false, false);
        if (TAG_CLICK_TELE.equals(tag_click)) {
            ConstantDataUnit cl_kfdh = getConstantDataByKey(Constants.cl_kfdh);
            if (cl_kfdh != null) {
                String telNum = cl_kfdh.getVal();
                IntentUtil.CallPhone(WebViewPage.this, telNum);
            }
        } else if (TAG_CLICK_QQ.equals(tag_click)) {

        }
    }

    /**
     * 获取用户信息
     */
    private void getuserinfo() {
        params.clear();
        params.put("token", getToken());
        getDate(params, Constants.USERINFOQUERY, handler, GET_USERINFO_SSUCESS, GET_USERINFO_FAIL,
            false, false, false);
    }

    /**
     * 获取项目详情(直投项目)
     */
    public void getProjectDetail(String type, String mode, String projectId) {

        params.clear();
        params.put("projectId", projectId);
        params.put("type", type);
        params.put("mode", mode);
        params.put("token", getToken());
        getDate(params, Constants.PROJECTINFOQUERY, handler, GETDETAILSUCCES, GETDETAILFAIL, true,
            true, true);
    }

    /**
     * 获取项目详情(转让项目)
     */
    public void getDebtProjectDetail(String bid) {

        params.clear();
        params.put("bId", bid);
        params.put("token", getToken());
        getDate(params, Constants.BONDINFOQUERY, handler, GETDEBTDETAILSUCCES, GETDEBTDETAILFAIL,
            true, true, true);
    }

    public class MyWebChromeClient extends WebChromeClient {
        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            sub_title_center_tv.setText("" + title);
        }

        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                web_progressbar_title.setVisibility(View.GONE);
            } else {
                web_progressbar_title.setVisibility(View.VISIBLE);
                web_progressbar_title.setProgress(newProgress);
            }
        }

    }

    @Override
    public void onDestroy() {
        mWebView.setVisibility(View.GONE);
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
        super.onDestroy();
    }

    @Override
    protected void findViewById(View view) {
        web_root = view.findViewById(R.id.web_root);
        mWebView = (WebView) view.findViewById(R.id.webview);
        sub_title_center_tv = (TextView) view.findViewById(R.id.sub_title_center_tv);
        sub_title_left_ll = (LinearLayout) view.findViewById(R.id.sub_title_left_ll);
        sub_title_left_bt = (ImageView) view.findViewById(R.id.sub_title_left_bt);
        sub_title_right_bt = (ImageView) view.findViewById(R.id.sub_title_right_bt);
        sub_title_right_tv = (TextView) view.findViewById(R.id.sub_title_right_tv);

        web_progressbar_title = (ProgressBar) view.findViewById(R.id.web_progressbar_title);
        to_inverst = (Button) view.findViewById(R.id.to_inverst);
        ll_bottom = (LinearLayout) view.findViewById(R.id.ll_bottom);
        sub_title_left_bt.setVisibility(View.VISIBLE);
        web_progressbar_title.setVisibility(View.VISIBLE);
        to_inverst.setOnClickListener(this);
        project_detail_remainder = (TextView) view.findViewById(R.id.project_detail_remainder);

        //避免键盘遮挡输入框
        getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                    | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    }

    @Override
    protected View loadViewLayout(LayoutInflater inflater) {
        View contactsLayout = inflater.inflate(R.layout.web_view_page, null);
        return contactsLayout;
    }

    @Override
    protected void onBackPress() {
        try {
            if (BACK_DIRECT.equals(back_mode)) {
                finish();
                overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
            } else if (BACK_TO_HOME.equals(back_mode)) {
                startNewActivity(new Intent(WebViewPage.this, HomeActivity.class).putExtra(
                    "BUTTON", R.id.radio_btn1), R.anim.push_right_in, R.anim.push_right_out, true);
            } else {
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                    return;
                }
                finish();
                overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
            }
        } catch (Exception e) {
            LogUtil.info(String.valueOf(e.getMessage()));
        }
    }

    class ContactClick implements ClickListener {

        @Override
        public void onClickLeft() {
            tag_click = TAG_CLICK_TELE;
            getContact();
        }

        @Override
        public void onClickRight() {
            tag_click = TAG_CLICK_QQ;
            //            getContact();
            new EaseHXUtils().startEaseChat(mContext);
        }

    }

}
